import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [{
    // 登录页面
    path: '/login',
    name: 'Login',
    component: () =>
        import ('@/views/login/App')
},
    {
        // 首页-暂时不指定 保留
        path: '/videoList',
        name: 'VideoList',
        component: () =>
            import ('@/views/videoList/App')
    },
    {
        path: '/',
        name: 'index',
        component: () =>
            import ('@/views/index/index')
    },
    {
        path: '/bigScreen',
        name: 'bigScreen',
        component: () =>
            import ('@/views/bigScreen/index')
    },
    {
        path: '/ceshi',
        name: 'ceshi',
        component: () =>
            import ('@/views/index/environment')
    },
    {
        path: '/choosePath',
        name: 'choosePath',
        component: () =>
            import ('@/views/chosePath')
    },
    {
        path: '/default',
        name: 'default',
        component: () =>
            import ('@/views/default/index')
    },
]

const router = new VueRouter({
    // mode: 'history',
    base: process.env.BASE_URL,
    routes
})

router.beforeEach((to, from, next) => {
    const token = sessionStorage.getItem('token');
    if ((to.path !== '/login' && token) || to.path === '/login' || to.path === '/choosePath' || to.path === '/default') {
        next();
    } else {
        next('/login');
    }
})

export default router
